<?php
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
if($_RQ['op']=='main'){
	$store=pdo_get('jy_weishop_store',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if(!$store['id']){
		$worker=pdo_get('jy_weishop_store_worker',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	}
	if(!$worker['id'] && !$store['id']){
		$current_plugin=$_SESSION['current_plugin']?:'jy_weishop';
		exi('你不是本店店员，无法登录','error',$current_plugin.'/index/');
	}
	$id=intval($_RQ['id']);
	$item=model('jy_weishop/order')->get_order($id);
	$item['status_title']=$this->order_status[$item['status']];
	if($item['addressid']){
		$item['step3title']='商家发货';
	}
	else if($item['isvirtualsend'] && $item['virtual']){
		$item['step3title']='自动发货';
	}else{
		$item['step3title']='确认取货';
	}
	if($item['isverify']==1){
		$item['sendtypetitle']='线下核销';
	}else if($item['addressid']){
		$item['sendtypetitle']='快递';
	}else if($item['isvirtualsend'] && $item['virtual']){
		$item['sendtypetitle']='自动发货(虚拟物品)';
	}else if($item['isverify']==1){
		$item['sendtypetitle']='线下核销';
	}else if($item['dispatchtype']){
		$item['sendtypetitle']='自提t';
	}else{
		$item['sendtypetitle']='其他';
	}
	$paytype=array('wechat'=>'微信支付','credit'=>'余额支付','hdfk'=>'货到付款');
	$ispay=array('0'=>'未支付','1'=>'已支付');
	$item['paytype']=$paytype[$item['paytype']]?$paytype[$item['paytype']]:'未支付';
	$item['ispay']=$ispay[$item['ispay']];
	$member=model('core/member')->detail($item['mid'],array('nickname','avatar','mobile'));
	$item=array_merge($member,$item);
	//$item['address']=model('core/member')->get_address_str($item['addressid']);
	$address=pdo_get('core_address',array('id'=>$item['addressid']));
	$address=array(
		'address'=>model('core/member')->get_address_str($item['addressid']),
		'address_en'=>model('core/member')->get_address_str($item['addressid'],true),
		'mobile'=>$address['mobile'],
		'name'=>$address['name'],
		'area_code'=>$address['area_code'],
	);
	$item=array_merge($item,$address);
	$item['createtime']=$item['createtime']?date('Y-m-d H:i:s',$item['createtime']):'';
	$item['payime']=$item['payime']?date('Y-m-d H:i:s',$item['payime']):'';
	$item['sendtime']=$item['sendtime']?date('Y-m-d H:i:s',$item['sendtime']):'';
	$item['finishtime']=$item['finishtime']?date('Y-m-d H:i:s',$item['finishtime']):'';
	$item['storetitle']=pdo_getcolumn('jy_weishop_store',array('id'=>$item['storeid']),'title')?:'无';
	$goods=pdo_getall('jy_weishop_order_goods',array('orderid'=>$item['id']),array('goodsid','price','total','optionid'));
	$item['orderprice']=$item['price'];
	$item['merchtitle']=pdo_getcolumn('jy_supplier_user',array('id'=>$item['api_id']),'merchname');
	foreach($goods as $k=>&$gv){
		$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$gv['goodsid']));
		$goodsinfo['title']=str_replace(',',' ',$goodsinfo['title']);
		$gv['title']=$goodsinfo['title'];
		$gv['goodssn']=$goodsinfo['goodssn'];
		$gv['productsn']=$goodsinfo['productsn'];
		$gv['subtitle']=$goodsinfo['subtitle'];
		$gv['unit']=$goodsinfo['unit'];
		$gv['merchtitle']=$item['merchtitle']?:'无';
		//商品规格
		if($gv['optionid']){
				$specs=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$gv['optionid']),'specs');
				$specs=explode("_",$specs);
				foreach($specs as &$spec){
					$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
				}
				$gv['selespename']=implode("，",$specs);
		}
		$newv['title']=$goodsinfo['title'];
		$newv['goodssn']=$goodsinfo['goodssn']?:'无';
		$newv['productsn']=$goodsinfo['productsn']?:'无';
		$newv['offcode']=$goodsinfo['offcode']?:'无';
		$newv['unit']=$goodsinfo['unit']?:'件';
		$newv['price']=$gv['price'];
		$newv['total']=$gv['total'];
		$newv['selespename']=$gv['selespename'];
		$newv=array_merge($item,$newv);
		$exdata[]=$newv;
	}
	$item['goods'] = $goods;
	$item['commission'] = pdo_get('jy_commission_member',array('mid'=>$item['mid']));
	$item['agent']=cfc('core')->member_show($item['commission']['agent_id'],'',array('nickname'=>'总店'));
	$item['agentmobile']=$item['agent']['mobile'];
	$item['agentname']=$item['agent']['nickname'];
	$return['item']=$item;
	$return['datime']=date('Y-m-d H:i:s');
	$return['basic']=$this->plugin_setting('basic');
	exi($return);
}
?>